import cv2
import time
import sys
import os
from camera import front_cam_Object
from camera import right_cam_Object, left_cam_Object
#摄像头编号 0是前摄像头，1是右摄像头，2是左摄像头
cam=1

btn=0
if __name__ == "__main__":
    if cam==0:
        result_dir="./fortress3"
        front_cam_Object.start()
        while True:
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
            else:
                path = "{}/{}.png".format(result_dir, btn)
                btn+=1
                time.sleep(0.2)
                image = front_cam_Object.read()
                name = "{}.png".format(btn)
                cv2.imwrite(path, image)
                print('taking picture')
    if cam==1:
        result_dir = "./right_image"
        right_cam_Object.start()
        while True:
            if cv2.waitKey(1) & 0xFF == ord('q'):
                sys.exit()
            else:
                path = "{}/{}.png".format(result_dir, btn)
                btn+=1
                time.sleep(0.2)
                image = right_cam_Object.read()
                name = "{}.png".format(btn)
                cv2.imwrite(path, image)
                print('taking picture')
    if cam==2:
        result_dir = "./dingxiangjun"
        left_cam_Object.start()
        while True:
            if cv2.waitKey(1) & 0xFF == ord('q'):
                sys.exit()
            else:
                path = "{}/{}.png".format(result_dir, btn)
                btn+=1
                time.sleep(0.2)
                image = left_cam_Object.read()
                name = "{}.png".format(btn)
                cv2.imwrite(path, image)
                print('taking picture')
    sys.exit()
# for i in range(100):
# 删除文件夹下的文件（图片）
# dirname ="./front_image"
# dellist = os.listdir(dirname)
# for f in dellist:               
#     file_path = os.path.join(dirname, f)
#     if os.path.isfile(file_path):
#         os.remove(file_path)
# print("delete successfully")